package algorithm;

/**
 * @author rongkai
 * @description: 给定一个排序数组，你需要在原地删除重复出现的元素，使得每个元素只出现一次
 * @date 2021/3/7
 */
public class Solution6 {

    public static void main(String[] args) {
        int[] array = {1,3,5,5,7,9,8};
        solution(array);
        for (int i : array) {
            System.out.println(i);
        }
    }

    /**
     * 借助另一个指针，当指针指向的值与上一个值不相等时就赋值否则就跳过
     * @param nums
     */
    public static int solution(int[] nums){
        int replacePosition = 1;
        for (int i = 1; i < nums.length; i++) {
            if (nums[i] != nums[i-1]){
                nums[replacePosition] = nums[i];
                replacePosition++;
            }
        }
        return replacePosition;

    }
}
